import { onlyPositiveNumberRules } from "@/utils/rules";
const validateNum = (rule, value, callback) => {
  if (!value) {
    callback(new Error("不能为空"));
  } else if (!onlyPositiveNumberRules.test(value)) {
    callback(new Error("只能为正整数"));
  } else {
    callback();
  }
};


export const ConfigType = [
  {
    name: "Normal",
    value: [
      {
        name: "imageOidList",
        type: "imageUpload",
        value: [],
        valueType: "array", // 若是多个图片则设置为array，单个图片则设置为number
        show: true,
        extra: {
          limit: 1,
          fileType: ["png", "jpg", "jpeg"],
          listType: "picture",
          who: "imageOidList",
          displayName: "imageOidListurl", // 图片URL反显字段
        },
      },
      {
        name: "vrImageOid",
        type: "select",
        value: "",
        valueType: "number",
        show: true,
        extra: {
          // limit: 1, // 单个图片的时候limit必须为1
          // fileType: ["png", "jpg", "jpeg"],
          // listType: "picture",
          // who: "vrImageOid",
          // displayName: "vrImageOidurl",
          placeholder: "请选择VR绑定数据",
          options: [],
        },
      },
      {
        name: "content",
        type: "richText",
        value: "",
        valueType: "string",
        show: true,
        extra: {},
      },
    ],
  },
  {
    name: "Shelf",
    value: [
      {
        name: "shelfNo",
        type: "input-number",
        value: "",
        valueType: "number",
        show: true,
        extra: {
          type: "number",
        },
      },
      {
        name: "rows",
        type: "input-number",
        value: "",
        valueType: "number",
        show: true,
        extra: {
          type: "number",
        },
      },
      {
        name: "cols",
        type: "input-number",
        value: "",
        valueType: "number",
        show: true,
        extra: {
          type: "number",
        },
      },
      {
        name: "side",
        type: "select",
        value: "",
        valueType: "string",
        show: true,
        extra: {
          placeholder: "请选择A/B面",
          options: [
            {
              label: "A面",
              value: "A",
            },
            {
              label: "B面",
              value: "B",
            },
          ],
        },
      },
      {
        name: "lastUpdate",
        type: "input",
        value: "",
        valueType: "string",
        show: false,
        extra: {
          type: "text",
        },
      },
    ],
  },
  {
    name: "None",
    value: [],
  },
  {
    name: "Custom",
    value: [],
  },
  {
    name: "RegularShelf",
    value: [],
  },
  {
    name: "Wall",
    value: [],
  },
  {
    name: "Link",
    value: [
      {
        name: "linkName",
        type: "input",
        value: "",
        valueType: "string",
        show: true,
        extra: {
          type: "text",
        },
      },
      {
        name: "linkUri",
        type: "input",
        value: "",
        valueType: "string",
        show: true,
        extra: {
          type: "text",
        },
      },
    ],
  },
];

export const sideArr = [
  {
    label: "A面",
    value: "A",
  },
  {
    label: "B面",
    value: "B",
  },
];

export const zhishuConfig = [
  {
    label: "appid",
    key: "appid",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入appid",
      rules: [{ required: true, message: "appid不能为空", trigger: "blur" }],
    },
  },
  {
    label: "appsecret",
    key: "appsecret",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入appsecret",
      rules: [
        { required: true, message: "appsecret不能为空", trigger: "blur" },
      ],
    },
  },
  {
    label: "合并书架",
    key: "group",
    type: "select",
    extra: {
      options: [
        {
          label: "是",
          value: true,
        },
        {
          label: "否",
          value: false,
        },
      ],
      placeholder: "请选择是否合并书架",
      rules: [{ required: true, message: "请选择合并书架", trigger: "change" }],
    },
  },
  {
    label: "api接口地址",
    key: "host",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入api接口地址",
      rules: [
        { required: true, message: "api接口地址不能为空", trigger: "blur" },
      ],
    },
  },
  {
    label: "书架分组",
    key: "locGroup",
    type: "input",
    extra: {
      defaultValue: "0",
      type: "text",
      placeholder: "请输入书架分组",
      rules: [{ required: true, message: "书架分组不能为空", trigger: "blur" }],
    },
  },
  {
    label: "token",
    key: "lastToken",
    type: "input",
    extra: {
      type: "text",
      rules: [],
      placeholder: "请输入token",
    },
  },
  {
    label: "token失效时间",
    key: "lastTokenExpire",
    type: "input",
    extra: {
      type: "text",
      rules: [],
      placeholder: "请输入token失效时间",
      timestamp: true,
    },
  },
];

export const syncConfig = [
  {
    label: "资产同步类型",
    key: "asset",
    type: "select",
    extra: {
      options: [],
      placeholder: "请选择资产同步类型",
      rules: [
        { required: false, message: "请选择资产同步类型", trigger: "change" },
      ],
    },
  },
  {
    label: "位置同步类型",
    key: "location",
    type: "select",
    extra: {
      options: [
        {
          label: "知书",
          value: "zhishu",
        },
        {
          label: "默认",
          value: "default",
        },
      ],
      placeholder: "请选择位置同步类型",
      rules: [
        { required: true, message: "请选择位置同步类型", trigger: "change" },
      ],
    },
  },
];

export const defaultLocateConfig = [
  {
    label: "状态过滤",
    key: "statusFilter",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入状态过滤",
      rules: [{ required: true, message: "状态过滤不能为空", trigger: "blur" }],
    },
  },
  {
    label: "馆藏地过滤",
    key: "orgFilter",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入馆藏地过滤",
      rules: [{ required: true, message: "馆藏地过滤不能为空", trigger: "blur" }],
    },
  },
  {
    label: "最大在架图书",
    key: "maxPerShelf",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入最大在架图书",
      rules: [{ required: true, validator: validateNum, trigger: "blur" }],
    },
  },
  {
    label: "分组",
    key: "group",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入分组",
      rules: [{ required: true, validator: validateNum, trigger: "blur" }],
    },
  }
]

export const referenceConfig = [
  {
    label: "名称",
    key: "name",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入名称",
      rules: [{ required: true, message: "名称不能为空", trigger: "blur" }],
    },
  },
  {
    label: "图标OID",
    key: "logoId",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入图标OID",
      rules: [{ required: true, message: "图标OID不能为空", trigger: "blur" }],
    },
  },
  {
    label: "外链地址",
    key: "url",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入外链地址",
      rules: [{ required: true, message: "外链地址不能为空", trigger: "blur" }],
    },
  },
]

export const featureConfig = [

]

export const virLibConfig = [
  {
    label: "vr链接地址",
    key: "vrUrl",
    type: "input",
    extra: {
      type: "text",
      placeholder: "请输入vr链接地址",
      rules: [{ required: true, message: "vr链接地址不能为空", trigger: "blur" }],
    },
  },
]

export const availableArr = [
  {
    key: "Zhishu",
    label: "知书",
    config: zhishuConfig,
    isSingle: true,
  },
  {
    key: "Sync",
    label: "同步",
    config: syncConfig,
    isSingle: true,
  },
  {
    key: "DefaultLocate",
    label: "默认定位",
    config: defaultLocateConfig,
    isSingle: true,
  },
  {
    key: "Reference",
    label: "外链配置",
    config: referenceConfig,
    isSingle: false,
  },
  {
    key: "Feature",
    label: "特性配置",
    config: featureConfig,
    isSingle: true,
  },
  {
    key: "VirLib",
    label: "虚拟馆配置",
    config: virLibConfig,
    isSingle: true,
  },
];
